package app.project.directionlensproject.map;

import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapFragment;
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;

import android.app.Activity;
import android.graphics.PixelFormat;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import app.project.directionlensproject.HomeActivity;
import app.project.directionlensproject.R;
import app.project.directionlensproject.model.Place;
import app.project.directionlensproject.util.Utilities;

public class MapLargeActivity extends Activity {

	private GoogleMap map;
	private ImageView mImageViewZoomPlace;
	LatLng MYPLACE;
	private Place mMyPlace;
	@Override
	public void onCreate(Bundle circle){
		super.onCreate(circle);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
//		getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
//				WindowManager.LayoutParams.FLAG_FULLSCREEN);
//		getWindow().setFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON,
//				WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
//		getWindow().setFormat(PixelFormat.RGBA_8888);
		setContentView(R.layout.activity_map_large);
		
		MYPLACE = new LatLng(HomeActivity.MY_LATITUDE,
				HomeActivity.MY_LONGITUDE);		
		createViewInit();
	}
	
	public void createViewInit(){
		
		mMyPlace = (Place) getIntent().getSerializableExtra("place");
		LatLng placeDetaiLatlng=new LatLng(mMyPlace.locationx, mMyPlace.locationy);
		mImageViewZoomPlace = (ImageView) findViewById(R.id.imageViewZoomMyPlaceLarge);
		
		map = ((MapFragment) getFragmentManager().findFragmentById(
				R.id.mapFragmentLarge)).getMap();
		map.moveCamera(CameraUpdateFactory.newLatLngZoom(placeDetaiLatlng, 20));

		MarkerOptions mkOptionUser = new MarkerOptions();
		mkOptionUser.position(MYPLACE);
		mkOptionUser.title("It's me");
		mkOptionUser.snippet("@@@");
		mkOptionUser.icon(BitmapDescriptorFactory
				.fromResource(R.drawable.ic_marker_my_place));

		MarkerOptions mkOptionPlace = new MarkerOptions();
		mkOptionUser.position(placeDetaiLatlng);
		mkOptionUser.title(mMyPlace.placename);
		mkOptionUser.snippet(mMyPlace.description);
		mkOptionUser.icon(Utilities.getInstance().getBitmapDescriptionFromType(mMyPlace.categoryid));
		
		map.addMarker(mkOptionUser);
		map.addMarker(mkOptionPlace);
		
		map.animateCamera(CameraUpdateFactory.zoomTo(15), 2000, null);
		
		mImageViewZoomPlace.setOnClickListener(new OnClickListener() {

			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				map.moveCamera(CameraUpdateFactory.newLatLngZoom(MYPLACE, 20));
				// Zoom in, animating the camera.
				map.animateCamera(CameraUpdateFactory.zoomTo(15), 2000, null);
			}
		});
		
	}
	
}
